
import config
import app.tools as tool
from PyQt4.QtCore import Qt
from PyQt4 import QtCore, QtGui
from app.ui import Icon


class Dialog(QtGui.QDialog):

    def __init__(self, parent=None, title=None):
        super(Dialog, self).__init__(parent)
        self.setWindowTitle(tool._from_utf8(title))
        self.icon = Icon()
        self.parent = parent
        self.logger = parent.logger

    def set_geometry(self, rect):
        self.setGeometry(rect)

    def set_window_size(self, percent=0.8):
        main_geometry = self.parent.geometry()
        main_width = main_geometry.width()
        main_height = main_geometry.height()
        width = main_width * percent
        height = main_height * percent
        left = main_geometry.left() + (main_width - width) / 2
        top = main_geometry.top() + (main_height - height) / 2
        rect = QtCore.QRect(left, top, width, height)
        self.setGeometry(rect)

    def show(self):
        if not self.isVisible():
            self.setWindowModality(Qt.WindowModal)
            super(Dialog, self).show()




